import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import { get_user_info } from './config';
import whoami from '@feidao/web/atom/browser/msg/whoami';
import nodejs from '@feidao/web/atom/browser/msg/nodejs';
import { send_msg as url } from './config';

//头部
export default async function (fd: IFeidaoAiBrowserComponent, ...args: any[]) {


	const user = await whoami(get_user_info) as {
		avatar_path: string;
		usercode: string;
		user_name: string;
	};

	console.log(user, '---------------------------')

	fd.data.node.querySelector('[data-feidao-name="user_name"]').innerHTML = user.user_name + ``;
	// if (user.avatar_path)
	// 	fd.data.node.querySelector<HTMLImageElement>('[data-feidao-name="msg"]').src = `${file_url}getfile?productid=${spaceid}&id=${user.avatar_path}`;

	const pathname = window.location.pathname;
	// const len = pathname.length;
	// const page_name = pathname.slice(1, len);
	const page_names = pathname.split('/');
	const len = page_names.length;

	const ind = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-index="index"]');
	const res = await nodejs<{ dataArray: Array<{}> }>(url, 'page_prompts_query1', {
		filter: {
			page_url: page_names[len - 1]
		}
	}, false, false);
	if (res.dataArray.length > 0) {
		ind.innerText = res.dataArray[0]['page_notes'];
	}
	// setInterval((() => {
	// 	const nowtime = new Date();
	// 	const year = nowtime.getFullYear();
	// 	const month = nowtime.getMonth() + 1;
	// 	const date = nowtime.getDate();
	// 	fd.data.node.querySelector<HTMLDivElement>('[data-feidao-time]').innerText = year + "年" + month + "月" + date + "日" + " " + nowtime.toLocaleTimeString('chinese', { hour12: false });
	// }), 1000);
	const name = fd.data.node.getAttribute('data-feidao-name');
	fd.data.node.querySelector('[data-feidao-id="name"]').innerHTML = name;
}

